package com.lino.design.factory;

import com.lino.design.workshop.ICacheAdapter;

import java.lang.reflect.Proxy;

/**
 * @description: 反射工厂
 * @author: lingjian
 * @createDate: 2022/12/16 15:17
 */
public class JDKProxyFactory {

    public static <T> T getProxy(Class<T> cacheClazz, Class<? extends ICacheAdapter> cacheAdapter) throws Exception {
        JDKInvocationHandler handler = new JDKInvocationHandler(cacheAdapter.newInstance());
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        return (T) Proxy.newProxyInstance(classLoader, new Class[]{cacheClazz}, handler);
    }
}
